package com.bp.exam.controller.supports;

import com.bianmaba.spring.mvc.method.support.annotations.EntityParam;
import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.Serializable;

/**
 * @program: bianmaba-web-framework-extends
 * @description:
 * @author: Chenjiabin
 * @create: 2018-04-23 20:05
 **/
public abstract class DefaultCrudController<T, ID extends Serializable> extends DefaultReadController<T, ID> {

    @ApiOperation(value = "保存", notes = "参数为JSON数据对象")
    @JSON
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public T save(@EntityParam T entity) {
        T result = getService().save(entity);
        return result;
    }

    @ApiOperation(value = "批量删除", notes = "根据ID集批量删除，返回true表示删除成功")
    @JSON()
    @RequestMapping(value = "/deletes", method = RequestMethod.POST)
    public boolean deletes(ID[] ids) {
        getService().delete(ids);
        return true;
    }

    @ApiOperation(value = "删除", notes = "根据ID删除，返回true表示删除成功")
    @JSON()
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public boolean delete(ID id) {
        getService().delete(id);
        return true;
    }
}
